// $ANTLR 3.4 C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g 2012-11-09 14:56:53

package PL.prac8;
import java.util.Hashtable;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

@SuppressWarnings({"all", "warnings", "unchecked"})
public class ExampleParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "APARENTESIS", "ASIGNACION", "ASTERISCO", "BARRA", "BLANCO", "CPARENTESIS", "DIGITO", "ESPACIO", "IDENT", "LETRA", "MAS", "MENOS", "NUEVA_LINEA", "NUMERO", "PUNTO", "PUNTOYCOMA"
    };

    public static final int EOF=-1;
    public static final int APARENTESIS=4;
    public static final int ASIGNACION=5;
    public static final int ASTERISCO=6;
    public static final int BARRA=7;
    public static final int BLANCO=8;
    public static final int CPARENTESIS=9;
    public static final int DIGITO=10;
    public static final int ESPACIO=11;
    public static final int IDENT=12;
    public static final int LETRA=13;
    public static final int MAS=14;
    public static final int MENOS=15;
    public static final int NUEVA_LINEA=16;
    public static final int NUMERO=17;
    public static final int PUNTO=18;
    public static final int PUNTOYCOMA=19;

    // delegates
    public Parser[] getDelegates() {
        return new Parser[] {};
    }

    // delegators


    public ExampleParser(TokenStream input) {
        this(input, new RecognizerSharedState());
    }
    public ExampleParser(TokenStream input, RecognizerSharedState state) {
        super(input, state);
    }

    public String[] getTokenNames() { return ExampleParser.tokenNames; }
    public String getGrammarFileName() { return "C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g"; }

    Hashtable variables = new Hashtable();


    // $ANTLR start "entrada"
    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:21:1: entrada : ( asignacion | instruccion )* EOF ;
    public final void entrada() throws RecognitionException {
        try {
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:21:9: ( ( asignacion | instruccion )* EOF )
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:21:11: ( asignacion | instruccion )* EOF
            {
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:21:11: ( asignacion | instruccion )*
            loop1:
            do {
                int alt1=3;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==IDENT) ) {
                    int LA1_2 = input.LA(2);

                    if ( (LA1_2==ASIGNACION) ) {
                        alt1=1;
                    }
                    else if ( ((LA1_2 >= ASTERISCO && LA1_2 <= BARRA)||(LA1_2 >= MAS && LA1_2 <= MENOS)||LA1_2==PUNTOYCOMA) ) {
                        alt1=2;
                    }


                }
                else if ( (LA1_0==APARENTESIS||LA1_0==NUMERO) ) {
                    alt1=2;
                }


                switch (alt1) {
            	case 1 :
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:21:12: asignacion
            	    {
            	    pushFollow(FOLLOW_asignacion_in_entrada59);
            	    asignacion();

            	    state._fsp--;


            	    }
            	    break;
            	case 2 :
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:21:23: instruccion
            	    {
            	    pushFollow(FOLLOW_instruccion_in_entrada61);
            	    instruccion();

            	    state._fsp--;


            	    }
            	    break;

            	default :
            	    break loop1;
                }
            } while (true);


            match(input,EOF,FOLLOW_EOF_in_entrada65); 

            }

        }
        catch (RecognitionException rre) {
          throw rre;}
         
        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "entrada"



    // $ANTLR start "asignacion"
    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:23:1: asignacion : i= igualacion ;
    public final void asignacion() throws RecognitionException {
        String i =null;


        try {
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:23:11: (i= igualacion )
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:23:13: i= igualacion
            {
            pushFollow(FOLLOW_igualacion_in_asignacion74);
            i=igualacion();

            state._fsp--;



            System.out.println("Asignacion "+i);

            }

        }
        catch (RecognitionException rre) {
          throw rre;}
         
        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "asignacion"



    // $ANTLR start "instruccion"
    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:25:1: instruccion : e= operacion ;
    public final void instruccion() throws RecognitionException {
        int e =0;


        try {
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:25:12: (e= operacion )
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:25:14: e= operacion
            {
            pushFollow(FOLLOW_operacion_in_instruccion84);
            e=operacion();

            state._fsp--;


            System.out.println ("Expresion: " + e);

            }

        }
        catch (RecognitionException rre) {
          throw rre;}
         
        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "instruccion"



    // $ANTLR start "igualacion"
    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:27:1: igualacion returns [String nombre = \"\";] : var= IDENT ASIGNACION e= expr PUNTOYCOMA ;
    public final String igualacion() throws RecognitionException {
        String nombre =  "";;


        Token var=null;
        int e =0;


        try {
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:27:41: (var= IDENT ASIGNACION e= expr PUNTOYCOMA )
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:27:42: var= IDENT ASIGNACION e= expr PUNTOYCOMA
            {
            var=(Token)match(input,IDENT,FOLLOW_IDENT_in_igualacion98); 

            match(input,ASIGNACION,FOLLOW_ASIGNACION_in_igualacion100); 

            pushFollow(FOLLOW_expr_in_igualacion104);
            e=expr();

            state._fsp--;


            match(input,PUNTOYCOMA,FOLLOW_PUNTOYCOMA_in_igualacion106); 

            variables.put(var.getText(),e); nombre = "("+var.getText()+"): "+ e;

            }

        }
        catch (RecognitionException rre) {
          throw rre;}
         
        finally {
        	// do for sure before leaving
        }
        return nombre;
    }
    // $ANTLR end "igualacion"



    // $ANTLR start "operacion"
    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:29:1: operacion returns [int res = 0] : e= expr PUNTOYCOMA ;
    public final int operacion() throws RecognitionException {
        int res =  0;


        int e =0;


        try {
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:29:32: (e= expr PUNTOYCOMA )
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:29:34: e= expr PUNTOYCOMA
            {
            pushFollow(FOLLOW_expr_in_operacion121);
            e=expr();

            state._fsp--;


            match(input,PUNTOYCOMA,FOLLOW_PUNTOYCOMA_in_operacion123); 

            res = e;

            }

        }
        catch (RecognitionException rre) {
          throw rre;}
         
        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "operacion"



    // $ANTLR start "expr"
    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:30:1: expr returns [int res=0] : e1= exp_mult ( ( MAS e2= exp_mult ) | ( MENOS e3= exp_mult ) )* ;
    public final int expr() throws RecognitionException {
        int res = 0;


        int e1 =0;

        int e2 =0;

        int e3 =0;


        try {
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:30:24: (e1= exp_mult ( ( MAS e2= exp_mult ) | ( MENOS e3= exp_mult ) )* )
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:30:26: e1= exp_mult ( ( MAS e2= exp_mult ) | ( MENOS e3= exp_mult ) )*
            {
            pushFollow(FOLLOW_exp_mult_in_expr136);
            e1=exp_mult();

            state._fsp--;


            res= e1;

            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:30:49: ( ( MAS e2= exp_mult ) | ( MENOS e3= exp_mult ) )*
            loop2:
            do {
                int alt2=3;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==MAS) ) {
                    alt2=1;
                }
                else if ( (LA2_0==MENOS) ) {
                    alt2=2;
                }


                switch (alt2) {
            	case 1 :
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:30:50: ( MAS e2= exp_mult )
            	    {
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:30:50: ( MAS e2= exp_mult )
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:30:51: MAS e2= exp_mult
            	    {
            	    match(input,MAS,FOLLOW_MAS_in_expr142); 

            	    pushFollow(FOLLOW_exp_mult_in_expr147);
            	    e2=exp_mult();

            	    state._fsp--;


            	    res= res + e2;

            	    }


            	    }
            	    break;
            	case 2 :
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:30:85: ( MENOS e3= exp_mult )
            	    {
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:30:85: ( MENOS e3= exp_mult )
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:30:86: MENOS e3= exp_mult
            	    {
            	    match(input,MENOS,FOLLOW_MENOS_in_expr152); 

            	    pushFollow(FOLLOW_exp_mult_in_expr157);
            	    e3=exp_mult();

            	    state._fsp--;


            	    res = res - e3;

            	    }


            	    }
            	    break;

            	default :
            	    break loop2;
                }
            } while (true);


            }

        }
        catch (RecognitionException rre) {
          throw rre;}
         
        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "expr"



    // $ANTLR start "exp_mult"
    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:31:1: exp_mult returns [int res=0] : e1= exp_base ( ( ASTERISCO e2= exp_base ) | ( BARRA e3= exp_base ) )* ;
    public final int exp_mult() throws RecognitionException {
        int res = 0;


        int e1 =0;

        int e2 =0;

        int e3 =0;


        try {
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:31:29: (e1= exp_base ( ( ASTERISCO e2= exp_base ) | ( BARRA e3= exp_base ) )* )
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:31:31: e1= exp_base ( ( ASTERISCO e2= exp_base ) | ( BARRA e3= exp_base ) )*
            {
            pushFollow(FOLLOW_exp_base_in_exp_mult175);
            e1=exp_base();

            state._fsp--;


            res=e1;

            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:31:53: ( ( ASTERISCO e2= exp_base ) | ( BARRA e3= exp_base ) )*
            loop3:
            do {
                int alt3=3;
                int LA3_0 = input.LA(1);

                if ( (LA3_0==ASTERISCO) ) {
                    alt3=1;
                }
                else if ( (LA3_0==BARRA) ) {
                    alt3=2;
                }


                switch (alt3) {
            	case 1 :
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:31:54: ( ASTERISCO e2= exp_base )
            	    {
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:31:54: ( ASTERISCO e2= exp_base )
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:31:55: ASTERISCO e2= exp_base
            	    {
            	    match(input,ASTERISCO,FOLLOW_ASTERISCO_in_exp_mult181); 

            	    pushFollow(FOLLOW_exp_base_in_exp_mult185);
            	    e2=exp_base();

            	    state._fsp--;


            	    res=res*e2;

            	    }


            	    }
            	    break;
            	case 2 :
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:31:93: ( BARRA e3= exp_base )
            	    {
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:31:93: ( BARRA e3= exp_base )
            	    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:31:94: BARRA e3= exp_base
            	    {
            	    match(input,BARRA,FOLLOW_BARRA_in_exp_mult192); 

            	    pushFollow(FOLLOW_exp_base_in_exp_mult196);
            	    e3=exp_base();

            	    state._fsp--;


            	    res=res/e3;

            	    }


            	    }
            	    break;

            	default :
            	    break loop3;
                }
            } while (true);


            }

        }
        catch (Exception ex) {

                                                System.out.println ("Error, no se puede dividir por cero");
                                                res = 0;
                                          
        }

        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "exp_mult"



    // $ANTLR start "exp_base"
    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:36:1: exp_base returns [int res= 0] : (n= NUMERO | APARENTESIS e= expr CPARENTESIS |var= IDENT );
    public final int exp_base() throws RecognitionException {
        int res =  0;


        Token n=null;
        Token var=null;
        int e =0;


        try {
            // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:36:31: (n= NUMERO | APARENTESIS e= expr CPARENTESIS |var= IDENT )
            int alt4=3;
            switch ( input.LA(1) ) {
            case NUMERO:
                {
                alt4=1;
                }
                break;
            case APARENTESIS:
                {
                alt4=2;
                }
                break;
            case IDENT:
                {
                alt4=3;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 4, 0, input);

                throw nvae;

            }

            switch (alt4) {
                case 1 :
                    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:36:33: n= NUMERO
                    {
                    n=(Token)match(input,NUMERO,FOLLOW_NUMERO_in_exp_base250); 

                    res = new Integer(n.getText()).intValue();

                    }
                    break;
                case 2 :
                    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:37:33: APARENTESIS e= expr CPARENTESIS
                    {
                    match(input,APARENTESIS,FOLLOW_APARENTESIS_in_exp_base288); 

                    pushFollow(FOLLOW_expr_in_exp_base292);
                    e=expr();

                    state._fsp--;


                    match(input,CPARENTESIS,FOLLOW_CPARENTESIS_in_exp_base294); 

                    res = e;

                    }
                    break;
                case 3 :
                    // C:\\Users\\Jose\\workspace\\prac8\\src\\main\\java\\PL\\prac8\\modulosantlr\\ExampleParser.g:38:33: var= IDENT
                    {
                    var=(Token)match(input,IDENT,FOLLOW_IDENT_in_exp_base334); 

                    res = (Integer) variables.get(var.getText());

                    }
                    break;

            }
        }
        catch (RecognitionException rre) {
          throw rre;}
         
        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "exp_base"

    // Delegated rules


 

    public static final BitSet FOLLOW_asignacion_in_entrada59 = new BitSet(new long[]{0x0000000000021010L});
    public static final BitSet FOLLOW_instruccion_in_entrada61 = new BitSet(new long[]{0x0000000000021010L});
    public static final BitSet FOLLOW_EOF_in_entrada65 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_igualacion_in_asignacion74 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_operacion_in_instruccion84 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_IDENT_in_igualacion98 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_ASIGNACION_in_igualacion100 = new BitSet(new long[]{0x0000000000021010L});
    public static final BitSet FOLLOW_expr_in_igualacion104 = new BitSet(new long[]{0x0000000000080000L});
    public static final BitSet FOLLOW_PUNTOYCOMA_in_igualacion106 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_expr_in_operacion121 = new BitSet(new long[]{0x0000000000080000L});
    public static final BitSet FOLLOW_PUNTOYCOMA_in_operacion123 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_exp_mult_in_expr136 = new BitSet(new long[]{0x000000000000C002L});
    public static final BitSet FOLLOW_MAS_in_expr142 = new BitSet(new long[]{0x0000000000021010L});
    public static final BitSet FOLLOW_exp_mult_in_expr147 = new BitSet(new long[]{0x000000000000C002L});
    public static final BitSet FOLLOW_MENOS_in_expr152 = new BitSet(new long[]{0x0000000000021010L});
    public static final BitSet FOLLOW_exp_mult_in_expr157 = new BitSet(new long[]{0x000000000000C002L});
    public static final BitSet FOLLOW_exp_base_in_exp_mult175 = new BitSet(new long[]{0x00000000000000C2L});
    public static final BitSet FOLLOW_ASTERISCO_in_exp_mult181 = new BitSet(new long[]{0x0000000000021010L});
    public static final BitSet FOLLOW_exp_base_in_exp_mult185 = new BitSet(new long[]{0x00000000000000C2L});
    public static final BitSet FOLLOW_BARRA_in_exp_mult192 = new BitSet(new long[]{0x0000000000021010L});
    public static final BitSet FOLLOW_exp_base_in_exp_mult196 = new BitSet(new long[]{0x00000000000000C2L});
    public static final BitSet FOLLOW_NUMERO_in_exp_base250 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_APARENTESIS_in_exp_base288 = new BitSet(new long[]{0x0000000000021010L});
    public static final BitSet FOLLOW_expr_in_exp_base292 = new BitSet(new long[]{0x0000000000000200L});
    public static final BitSet FOLLOW_CPARENTESIS_in_exp_base294 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_IDENT_in_exp_base334 = new BitSet(new long[]{0x0000000000000002L});

}